#include <stdio.h>
#include <SDL/SDL.h>


void jouer(SDL_Surface *screen)
{
    SDL_Surface *image,*gagne,*perdu;
    SDL_Surface *num1,*num0,*select;
    SDL_Rect PosApui,Pos,pos1,posgagne;

    int continuer=1;
    int i=5;
    int j,k;

    int tab [4][4];
    SDL_Event event;
     screen= SDL_SetVideoMode(600, 404, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
     image = SDL_LoadBMP("image.bmp");
    select=SDL_LoadBMP("select.bmp");
    num0=SDL_LoadBMP("0.bmp");
    num1=SDL_LoadBMP("1.bmp");
    gagne=SDL_LoadBMP("gagne.bmp");
    perdu=SDL_LoadBMP("perdu.bmp");
    SDL_SetColorKey(gagne,SDL_SRCCOLORKEY,SDL_MapRGB(gagne->format,255,255,255));
    SDL_SetColorKey(perdu,SDL_SRCCOLORKEY,SDL_MapRGB(perdu->format,255,255,255));

    {
                            pos1.x=349;
                            pos1.y=128;
                            SDL_BlitSurface(num1,NULL,image,&pos1);
                            }

{

                                Pos.x=287;
                                Pos.y=227;
                               SDL_BlitSurface(num0,NULL,image,&Pos);

                            }
                            {Pos.x=167;
                                Pos.y=228;
                                   SDL_BlitSurface(num1,NULL,image,&Pos);


                            }

                            {Pos.x=349;
                                Pos.y=228;
                                   SDL_BlitSurface(num0,NULL,image,&Pos);


                            }
                            {Pos.x=167;
                                Pos.y=128;
                                   SDL_BlitSurface(num1,NULL,image,&Pos);


                            }
                            {Pos.x=167;
                                Pos.y=128;
                                   SDL_BlitSurface(num1,NULL,image,&Pos);


                            }
                            {Pos.x=226;
                                Pos.y=128;
                                   SDL_BlitSurface(num0,NULL,image,&Pos);


                            }













    while (continuer)
    {
         SDL_WaitEvent(&event);
         switch(event.type)
         {
             case SDL_QUIT:
            continuer= 0;
            break;
            case (SDL_MOUSEBUTTONDOWN):



                            if (((event.button.x)>167)&&(event.button.x<217)&&((event.button.y)>77)&&(((event.button.y)<120)))
                            {
                                PosApui.x=167;
                                PosApui.y=77;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                                j=0;
                                k=0;
                            }
                            if (((event.button.x)>226)&&(event.button.x<276)&&((event.button.y)>77)&&(((event.button.y)<120)))
                            {
                                PosApui.x=226;
                                PosApui.y=77;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                                j=0;
                                k=1;
                            }
                            if (((event.button.x)>287)&&(event.button.x<337)&&((event.button.y)>77)&&(((event.button.y)<120)))
                            {
                                PosApui.x=287;
                                PosApui.y=77;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                                j=0;
                                k=2;
                            }
                            if (((event.button.x)>349)&&(event.button.x<399)&&((event.button.y)>77)&&(((event.button.y)<120)))
                            {
                                PosApui.x=349;
                                PosApui.y=77;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                                j=0;
                                k=3;
                            }
                             if (((event.button.x)>166)&&(event.button.x<217)&&((event.button.y)>179)&&(((event.button.y)<219)))
                            {
                                PosApui.x=166;
                                PosApui.y=179;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                                j=2;
                                k=0;


                            }




                            if (((event.button.x)>287)&&(event.button.x<337)&&((event.button.y)>129)&&(((event.button.y)<169)))
                            {
                                PosApui.x=287;
                                PosApui.y=128;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                                j=1;
                                k=2;
                            }




                            if (((event.button.x)>166)&&(event.button.x<217)&&((event.button.y)>179)&&(((event.button.y)<220)))
                            {
                                PosApui.x=166;
                                PosApui.y=179;
                                SDL_BlitSurface(select,NULL,image,&PosApui);

                            }



                            if (((event.button.x)>226)&&(event.button.x<277)&&((event.button.y)>179)&&(((event.button.y)<219)))
                            {
                                PosApui.x=226;
                                PosApui.y=179;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                                j=2;
                                k=1;
                            }



                            if (((event.button.x)>287)&&(event.button.x<337)&&((event.button.y)>178)&&(((event.button.y)<220)))
                            {
                                PosApui.x=287;
                                PosApui.y=178;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                                j=2;
                                k=2;
                            }



                            if (((event.button.x)>350)&&(event.button.x<399)&&((event.button.y)>179)&&(((event.button.y)<219)))
                            {
                                PosApui.x=350;
                                PosApui.y=179;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                                j=2;
                                k=3;
                            }



                            if (((event.button.x)>226)&&(event.button.x<275)&&((event.button.y)>229)&&(((event.button.y)<271)))
                            {
                                PosApui.x=226;
                                PosApui.y=229;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                                j=3;
                                k=1;
                            }




                             /*if (((event.button.x)>226)&&(event.button.x<276)&&((event.button.y)>127)&&(((event.button.y)<169)))
                            {
                                PosApui.x=226;
                                PosApui.y=127;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                            }if (((event.button.x)>286)&&(event.button.x<336)&&((event.button.y)>129)&&(((event.button.y)<179)))
                            {
                                PosApui.x=286;
                                PosApui.y=129;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                                }


                                if (((event.button.x)>227)&&(event.button.x<276)&&((event.button.y)>178)&&(((event.button.y)<219)))
                            {
                                PosApui.x=227;
                                PosApui.y=178;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                            }
                                if (((event.button.x)>226)&&(event.button.x<275)&&((event.button.y)>179)&&(((event.button.y)<270)))
                            {
                                PosApui.x=226;
                                PosApui.y=179;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                            }
                               if (((event.button.x)>225)&&(event.button.x<275)&&((event.button.y)>227)&&(((event.button.y)<269)))
                            {
                                PosApui.x=226;
                                PosApui.y=228;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                            }
                              if (((event.button.x)>286)&&(event.button.x<337)&&((event.button.y)>127)&&(((event.button.y)<220)))
                            {
                                PosApui.x=286;
                                PosApui.y=127;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                            }
                            /*if (((event.button.x)>287)&&(event.button.x<337)&&((event.button.y)>270)&&(((event.button.y)<267)))
                            {
                                PosApui.x= 287;
                                PosApui.y= 178;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                            }
                            if (((event.button.x)>287)&&(event.button.x<339)&&((event.button.y)>178)&&(((event.button.y)<170)))
                            {
                                PosApui.x= 287;
                                PosApui.y= 178;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                            }
                            if (((event.button.x)>287)&&(event.button.x<398)&&((event.button.y)>178)&&(((event.button.y)<220)))
                            {
                                PosApui.x= 287;
                                PosApui.y= 178;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                            }
                            if (((event.button.x)>287)&&(event.button.x<399)&&((event.button.y)>178)&&(((event.button.y)<270)))
                            {
                                PosApui.x= 287;
                                PosApui.y= 178;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                            }
                            if (((event.button.x)>287)&&(event.button.x<399)&&((event.button.y)>178)&&(((event.button.y)<120)))
                            {
                                PosApui.x= 287;
                                PosApui.y= 178;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                            }
                            if (((event.button.x)>278)&&(event.button.x<399)&&((event.button.y)>228)&&(((event.button.y)<120)))
                            {
                                PosApui.x= 278;
                                PosApui.y= 228;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                            }
                             if (((event.button.x)>348)&&(event.button.x<399)&&((event.button.y)>170)&&(((event.button.y)<128)))
                            {
                                PosApui.x=348 ;
                                PosApui.y=178 ;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                            }
                            if (((event.button.x)>349)&&(event.button.x<399)&&((event.button.y)>178)&&(((event.button.y)<270)))
                            {
                                PosApui.x=349 ;
                                PosApui.y=178 ;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                            }
                            if (((event.button.x)>287)&&(event.button.x<336)&&((event.button.y)>227)&&(((event.button.y)<270)))
                            {
                                PosApui.x=287 ;
                                PosApui.y=227 ;
                                SDL_BlitSurface(select,NULL,image,&PosApui);
                            }*/
















                            break;
            case SDL_KEYDOWN:

            switch (event.key.keysym.sym)
            {
            case SDLK_0:
                i=0;
                tab[j][k]=i;
            break;
            case SDLK_1:
                i=1;
                tab[j][k]=i;
            break;
            case SDLK_ESCAPE:
                continuer=0;
            break;
            }

         break;
    }




    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255,255));
        SDL_BlitSurface(image, NULL, screen,NULL);

switch(i)
 {
case 0:
        SDL_BlitSurface(num0, NULL, image, &PosApui);
    break;


break;
 case 1:

    SDL_BlitSurface(num1, NULL, image, &PosApui);
break;
 }

 if((tab[0][0]==0)&&(tab[0][1]==1)&&(tab[0][2]==1)&&(tab[0][3]==0)&& (tab[1][2]==0)&&(tab[2][0]==0)&&(tab[2][1]==0)&&(tab[2][2]==1)&&(tab[2][3]==1)&&(tab[3][1]==1))
 {
     SDL_BlitSurface(gagne,NULL,image,NULL);
 }
 /*else SDL_BlitSurface(perdu,NULL,image,NULL);*/
    SDL_Flip(screen);
    }
        /*SDL_Quit();*/
         SDL_FreeSurface(image);
    }







